#include <bits/stdc++.h>
using namespace std;

#define int long long

vector<int> eulerSieve(int n) {
    vector<int> prime;
    vector<bool> flag(n + 1);
    for (int i = 2; i <= n; i++) {
        if (!flag[i]) {
            prime.push_back(i);
        }
        //保证每个数都被最小的质数筛除
        for (int j = 0; j < prime.size(); j++) {
            //第一个条件是小于等于n，而第二个条件是保证被最小的质数筛除
            if (i * prime[j] > n) break;
            flag[i * prime[j]] = true;
            if (i % prime[j] == 0) break;
        }
    }
    return prime;
}

signed main() {
    int n;
    cout << "输入要求质数的最大值：";
    cin >> n;
    vector<int> prime = eulerSieve(n);
    for (int i = 0; i < prime.size(); i++) {
        cout << prime[i] << " ";
    }
    cout << endl;
    return 0;
}